﻿@page "/_StudentMajor/StudentMajor/Create"
@using WBBvNext.ViewModel._StudentMajor.StudentMajorVMs;
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.FormRow">

            <Select @bind-Value="@Model.Entity.MajorId" Items="@AllMajors" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]"/>
            <Select @bind-Value="@Model.Entity.StudentId" Items="@AllStudents" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]"/>
    </Row>
    <div class="modal-footer table-modal-footer">
        <Button Color="Color.Primary" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Close"]" OnClick="OnClose" />
        <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Create"]" IsAsync="true" />
    </div>
</ValidateForm>

@code {

    private StudentMajorVM Model = new StudentMajorVM();
    private ValidateForm vform { get; set; }

    private List<SelectedItem> AllMajors = new List<SelectedItem>();

    private List<SelectedItem> AllStudents = new List<SelectedItem>();


    protected override async Task OnInitializedAsync()
    {

        AllMajors = await WtmBlazor.Api.CallItemsApi("/api/StudentMajor/GetMajors", placeholder: WtmBlazor.Localizer["Sys.PleaseSelect"]);

        AllStudents = await WtmBlazor.Api.CallItemsApi("/api/StudentMajor/GetStudents", placeholder: WtmBlazor.Localizer["Sys.PleaseSelect"]);

        await base.OnInitializedAsync();
    }


    private async Task Submit(EditContext context)
    {
        await PostsForm(vform, "/api/StudentMajor/add", (s) => "Sys.OprationSuccess");
    }

    public void OnClose()
    {
        CloseDialog();
    }

}
